#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sqlite3.h>

static int myfunc(void *p, int argc, char **argv, char **argvv)
{
	int i;
	*(int *)p= 0;
	printf("\n");
	for (i = 0; i < argc; ++i)
		printf("%s = %s ", argvv[i], argv[i] ? argv[i] :"NULL");
	printf("\n");
	return 0;
}

int main()
{
	sqlite3 *db;
	char *err =0;
	int ret_sqlite =0;// 记录表的长度，单次执行时有效
	int empty =1;

	printf("Content-type: text/html\n\n" );
	printf("<html>\n");
	printf("<head>\n");
	printf("<title>CGI_OPEN</title>\n");
	printf("<head><meta http-equiv=\"refresh\" content=\"1;url=HB_CGI.cgi\"></head>");
	printf("</head>\n");
	printf("<body>");
	printf("<center>");
	
	// 与数据库建立连接，查看数据库内容
	ret_sqlite = sqlite3_open("/var/www/xuedao", &db);
	if(ret_sqlite != SQLITE_OK)
	{
		printf("sqlite3 open error\n");
		exit(1);
	}
	printf("<center>");
	printf("<h1> 小青蛙智慧农场灯光开 </h1>");
	printf("<font size = \"6\">打开灯光</font>");
	ret_sqlite = sqlite3_exec(db, "delete from hb_open",NULL, &empty, &err);
	ret_sqlite = sqlite3_exec(db, "insert into hb_open values(1)", NULL, &empty, &err);
	printf("</center>");
	
	printf("</body>");
	printf("</html>");
	
	return 0;
}

